package com.campus.dao;

import com.campus.pojo.SysArea;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface SchoolDao {
    @Select("select * from sys_area where type=1 and delState=1 order by sortNum")
    List<SysArea> getParentAreaList();  //获取所有省

    @Select("select * from sys_area where parentId=#{parentId} and delState=1 order by sortNum")
    List<SysArea> getChildrenAreaList(String parentId);    //根据父节点获取子节点

    @Select("select * from sys_area where areaNumber = #{areaNumber} and delState=1")
    SysArea getSelectedArea(String areaNumber); //根据区域号查找区域

    @Select("select name from sys_area where areaNumber=#{parentId} and delState=1")
    String selectParentName(String parentId);   //查找父节点名称

    @Update("update sys_area set name=#{name},parentId=#{parentId},isLeaf=#{isLeaf},sortNum=#{sortNum},type=#{type} " +
            "where areaNumber=#{areaNumber}")
    int updateSchool(SysArea sysArea);  //更新学校

    @Select("select count(*) from sys_area where areaNumber <> #{areaNumber} and name = #{name}")
    int isRepeatName(SysArea area);//判断重名

    @Select("select count(*) from sys_area where areaNumber = #{areaNumber}")
    int isRepeatAreaNumber(SysArea area);//判断areaNumber重复

    @Insert("INSERT INTO sys_area(areaNumber, name, type, parentId, isLeaf, sortNum, delState) " +
            "VALUES (#{areaNumber},#{name},#{type},#{parentId},#{isLeaf},#{sortNum},1)")
    int addSchool(SysArea area);//添加学校

    @Update("UPDATE sys_area set delState=2 where areaNumber in (${ids})")
    int delSchool(@Param("ids") String ids);//批量删除
}
